package weixin_new.service;


import base.Until.Token;
import base.pojo.menu.Button;
import base.pojo.menu.ClickButton;
import base.pojo.menu.ComplexButton;
import base.pojo.menu.Menu;
import base.pojo.menu.ViewButton;
import base.Until.CommonUtil;
import base.Until.ConfigUtil;
import base.Until.MenuUtil;


/**
 * 菜单管理器类
 * https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=5_5LDCK9KSxv7jK2MaokVPfnQ6ek9CSTtfUaTx8OCn_7DCSl9ldF3QiLEPXxJtA5N73UtOOx_pM3DxN2KuMtx3oeCwIqyrUoA4vdW0z2rjwXVU4YGm686sm1vXTRTDq6UxxrX3MckHDCXbgObGXNAbAJAPFS&type=news&offset=0&count=20
 * 
 */
public class MenuManager {

	/**
	 * 定义菜单结构
	 * 
	 * @return
	 */
	private static Menu getMenu() {
		ViewButton btn11 = new ViewButton();
		btn11.setName("小蚁安德");
		btn11.setType("view");
		btn11.setUrl("http://mp.weixin.qq.com/s?__biz=MzU4MzAxMTA5OQ==&mid=100000042&idx=1&sn=8c6d154273e844e6f75177fecc69fc07&chksm=7daedf5e4ad95648df856eeeac29650adbc080f8bf312d7b2c31bac82832cb67d7cf47f29fa8#rd");

		ViewButton btn12 = new ViewButton();
		btn12.setName("感之度");
		btn12.setType("view");
		btn12.setUrl("http://mp.weixin.qq.com/s?__biz=MzU4MzAxMTA5OQ==&mid=100000022&idx=1&sn=f59214937b91aff19d454df6cd5a6e99&chksm=7daedf624ad956741d214e06e9b862e0aa1b4f8af2fd62ffd49b54c6d5817985c3e4384ad78d#rd");




		ViewButton btn21 = new ViewButton();
		btn21.setName("小蚁安迪");
		btn21.setType("view");
		btn21.setUrl("http://mp.weixin.qq.com/s?__biz=MzU4MzAxMTA5OQ==&mid=100000052&idx=1&sn=84b703ce0aa34126387678b0cc2b4c92&chksm=7daedf404ad956566ee76d7b6e963a696b04bf4b82c10729f13dde812dce395d3685b1c5e444#rd");

		ViewButton btn22 = new ViewButton();
		btn22.setName("哆啦A梦");
		btn22.setType("view");
		btn22.setUrl("http://mp.weixin.qq.com/s?__biz=MzU4MzAxMTA5OQ==&mid=100000184&idx=1&sn=2b4d7a836666ca1fd3abf228887f2511&chksm=7daedfcc4ad956da9715f3d91b044055cce18b13d876697623dc512d493c287d2df7979b0d5b#rd");
		
		ViewButton btn23 = new ViewButton();
		btn23.setName("莱思纽卡");
		btn23.setType("view");
		btn23.setUrl("http://mp.antradars.com/myapp/jsp/shouye/index.html?id=83&from=singlemessage");
		

		ViewButton btn31 = new ViewButton();
		btn31.setName("育儿天地");
		btn31.setType("view");
		btn31.setUrl("http://mp.antradars.com/myapp/jsp/shouye/wzlb.html");


		ViewButton btn32 = new ViewButton();
		btn32.setName("每日一图");
		btn32.setType("view");
		btn32.setUrl("http://mp.antradars.com/myapp/jsp/mryt/index.html");


		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("智能体温");
		mainBtn1.setSub_button(new Button[] { btn11, btn12});

		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("儿童营养");
		mainBtn2.setSub_button(new Button[] { btn21,btn22,btn23});

		ComplexButton mainBtn3 = new ComplexButton();
		mainBtn3.setName("会员天地");
		mainBtn3.setSub_button(new Button[] { btn31, btn32 });

		Menu menu = new Menu();
		menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });

		return menu;
	}

	public static void main(String[] args) {
//		// 第三方用户唯一凭证
		String appId =ConfigUtil.APPID;
//		// 第三方用户唯一凭证密钥
		String appSecret = ConfigUtil.APP_SECRECT;
//
//		// 调用接口获取凭证
	   Token token = CommonUtil.getToken(appId, appSecret);

		System.out.println( token.getAccessToken());

		if (null != token) {
			// 创建菜单
			boolean result = MenuUtil.createMenu(getMenu(), token.getAccessToken());

			// 判断菜单创建结果
			if (result)
				System.out.println("菜单创建成功！");
			else
				System.out.println("菜单创建失败！");
	}
	
	//获得素材列表
		String xlml ="{\"type\":\"news\", \"offset\":\"0\",\"count\":\"20\"}";
		String result2 = MenuUtil.Query_wznr(xlml, token.getAccessToken());
		System.out.println( result2);
		
	}
}
